fix: improve script restart behavior for multi-instance setups#2194
Merged
GermanBluefox merged 2 commits intoioBroker:masterfrom Apr 11, 2026
Merged
fix: improve script restart behavior for multi-instance setups#2194GermanBluefox merged 2 commits intoioBroker:masterfrom
GermanBluefox merged 2 commits intoioBroker:masterfrom
Conversation
Prevents duplicate 'Stopping script' logs by early-returning when script is not running. Restricts restart handling to the owning instance only. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two issues that occur when running multiple JavaScript adapter instances:
Problem 1: Duplicate "Stopping script" log messages
When
stopScript()was called for a script that was not running on the current instance, it would still logStopping scriptand attempt to set thescriptEnabledstate — even though there was nothing to stop. This caused confusing duplicate log entries.Fix: Added an early return in
stopScript()that checksthis.scripts[name]before proceeding. If the script is not loaded on this instance, it returnsfalseimmediately without logging or side effects.Problem 2: Unnecessary script restarts on unrelated instances
When a script's source code was changed (e.g., saved in the editor), the
onObjectChangehandler would trigger a stop/restart cycle on every JavaScript adapter instance — not just the one that owns the script. This led to unnecessary restart attempts and confusing log output on instances that don't run the script.Fix: Changed the unconditional
elsebranch inonObjectChangeto anelse ifthat checks whether the script's engine (current or former) matchessystem.adapter.${this.namespace}. Only the owning instance now reacts to source changes.Changes
src/main.ts: Early return instopScript()when script is not runningsrc/main.ts: Instance-scoped restart inonObjectChangefor script source changesbuild/main.js: Compiled output matching the source changesREADME.md: Changelog entries under WORK IN PROGRESSTest plan
javascript.0andjavascript.1)javascript.0, save/edit itjavascript.0logs "Stopping script" / restart —javascript.1stays silentnpm run testpasses (41 integration tests)npm run lintpasses onsrc/main.ts🤖 Generated with Claude Code